App.js ➔ onIpcFrom   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
const { app, ipcMain } = require('electron');
2
const path = require("path");
0 ignored issues
show
Unused Code introduced by
The constant path seems to be never used. Consider removing it.
Loading history...
3
const Window = require("./Window");
0 ignored issues
show
Unused Code introduced by
The constant Window seems to be never used. Consider removing it.
Loading history...
4
const AppMenu = require("./AppMenu");
0 ignored issues
show
Unused Code introduced by
The constant AppMenu seems to be never used. Consider removing it.
Loading history...
5
const Store = require('electron-store');
0 ignored issues
show
Unused Code introduced by
The constant Store seems to be never used. Consider removing it.
Loading history...
6
const EventEmitter = require('events');
0 ignored issues
show
Unused Code introduced by
The constant EventEmitter seems to be never used. Consider removing it.
Loading history...
7
const SaveFile = require('./SaveFile');
0 ignored issues
show
Unused Code introduced by
The constant SaveFile seems to be never used. Consider removing it.
Loading history...
8
9
/**
10
 * App Singleton (Wrapper around electron app singleton var)
11
 */
12
module.exports = class App extends EventEmitter {
13
    constructor() {
14
        super();
15
16
        // Make Single Instance and ensure single instance
17
        // if (app.requestSingleInstanceLock()) {
18
        //     this.quit();
19
        //     return;
20
        // }
21
        //app.on('second-instance', this.onSecondInstance.bind(this));
22
23
        // Electron app var
24
        this.app = app;
25
26
        // Window
27
        this.mainWindow = null;
28
29
        // Is development or not
30
        this.isDev = process.env.DEV
31
            ? (process.env.DEV.trim() == "true")
32
            : false;
33
34
        // Adjust process working directory depending on dev enviroment or not
35
        if (this.isDev)
36
            process.chdir(path.join(__dirname, '../src'));
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable path seems to be never declared. If this is a global, consider adding a /** global: path */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
37
        else
38
            process.chdir(path.join(__dirname, '../dist/pokered-save-editor'));
39
40
        this.store = new Store();
0 ignored issues
show
Bug introduced by
The variable Store seems to be never declared. If this is a global, consider adding a /** global: Store */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
41
        this.saveFile = new SaveFile(this);
0 ignored issues
show
Bug introduced by
The variable SaveFile seems to be never declared. If this is a global, consider adding a /** global: SaveFile */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
42
43
        // App Icon
44
        this.icon = 'assets/icons/512x512.png';
45
46
        // Set Name
47
        app.setName("Pokered Save Editor");
48
49
        // App events to hook into for wrapper
50
        app.on('ready', this.createWindow.bind(this));
51
        app.on('window-all-closed', this.quit.bind(this));
52
53
        ipcMain.on('ipcFrom', this.onIpcFrom.bind(this));
0 ignored issues
show
Bug introduced by
The variable ipcMain seems to be never declared. If this is a global, consider adding a /** global: ipcMain */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
54
    }
55
56
    onIpcFrom(sender, event, ...args) {
57
        this.emit(`ipcFrom-${event}`, ...args);
58
    }
59
60
    onSecondInstance(argv, cwd) {
0 ignored issues
show
Unused Code introduced by
The parameter cwd is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter argv is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
61
        if (this.mainWindow)
62
            this.mainWindow.reOpen();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
63
    }
64
65
    createWindow() {
66
        // Menu must be called around this time so it's placed here
67
        this.menu = new AppMenu(this);
0 ignored issues
show
Bug introduced by
The variable AppMenu seems to be never declared. If this is a global, consider adding a /** global: AppMenu */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
68
        this.mainWindow = new Window(this);
0 ignored issues
show
Bug introduced by
The variable Window seems to be never declared. If this is a global, consider adding a /** global: Window */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
69
    }
70
71
    quit() {
72
        app.quit();
73
    }
74
}
75